package enums;

/**
 * 使用枚举表述常量数据字段
 * 
 * @author liuwj
 *
 */
public enum SeckillStateEnum {
	SUCCESS(1, "秒杀成功"), 
	END(0, "秒杀结束"), 
	REPEAT_KILL(-1, "重复秒杀"), 
	INNOR_ERROR(-2, "系统异常"), 
	DATA_REWRITE(-3, "数据篡改");

	private int state;

	private String stateInfo;

	private SeckillStateEnum(int state, String stateInfo) {
		this.state = state;
		this.stateInfo = stateInfo;
	}

	public int getState() {
		return state;
	}

	public String getStateInfo() {
		return stateInfo;
	}

	public static SeckillStateEnum stateOf(int index) {
		for (SeckillStateEnum stateInfo : values()) { // 迭代所有类型
			if (stateInfo.getState() == index) { // values() 可以拿到所有类型
				return stateInfo;
			}
		}
		return null;
	}
}
